﻿using System.Windows.Media;

namespace SuperFrame.Charts
{
    public class ContainerLine : SeriesContainer
    {

        public ContainerLine() : base()
        {
        }

        public override void Draw()
        {
            base.Draw();
        }

        override protected void DrawPath(BaseSeries series, System.Drawing.Pen pen)
        {
            if (series is SeriesLine)
            {
                var points = new PointCollection();
                var lowPoints = new PointCollection();
                var pointCount = 0;
                CollectionParts partsCollection = new CollectionParts();
                if (series is SeriesLine)
                {
                    SeriesLine lineSeries = series as SeriesLine;
                    points = lineSeries.LinePoints;
                    pointCount = lineSeries.LinePoints.Count;
                    partsCollection = lineSeries.Parts;
                }
                PartsCanvas.Children.Clear();
                if (RenderingMode == RenderingMode.Default)
                {
                    for (int i = 0; i < partsCollection.Count; i++)
                    {
                        PartsCanvas.Children.Add(partsCollection[i].CreatePart());
                        PartsCanvas.Children.Add(partsCollection[i].CreatePoint());
                    }
                    if (partsCollection.Count > 0)
                        PartsCanvas.Children.Add(partsCollection[partsCollection.Count - 1].CreateEndPoint());
                }
                else
                {
                    if (series is SeriesLine)
                    {
                        for (int i = 0; i < pointCount - 1; i++)
                        {

                            switch (RenderingMode)
                            {
                                case RenderingMode.GDIRendering:
                                    GDIGraphics.DrawLine(pen, points[i].AsDrawingPointF(), points[i + 1].AsDrawingPointF());
                                    break;
                                case RenderingMode.Default:
                                    break;
                                case RenderingMode.WritableBitmap:
                                    this.WritableBitmap.Lock();
                                    WritableBitmapGraphics.DrawLine(pen, points[i].AsDrawingPointF(), points[i + 1].AsDrawingPointF());
                                    this.WritableBitmap.Unlock();
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < pointCount; i++)
                        {

                            switch (RenderingMode)
                            {
                                case RenderingMode.GDIRendering:
                                    GDIGraphics.DrawLine(pen, points[i].AsDrawingPointF(), lowPoints[i].AsDrawingPointF());

                                    break;
                                case RenderingMode.Default:
                                    break;
                                case RenderingMode.WritableBitmap:
                                    this.WritableBitmap.Lock();
                                    WritableBitmapGraphics.DrawLine(pen, points[i].AsDrawingPointF(), lowPoints[i].AsDrawingPointF());
                                    this.WritableBitmap.Unlock();
                                    break;
                                default:
                                    break;
                            }
                        }
                    }
                    this.collection.InvalidateBitmap();
                }
            }
        }

    }
}
